package com.ycw.service.guoguo.impl;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.stereotype.Service;

import com.ycw.bean.Projects;
import com.ycw.bean.ProjectsType;
import com.ycw.bean.Users;
import com.ycw.dao.ProjectsMapper;
import com.ycw.dao.ProjectsTypeMapper;
import com.ycw.dao.UsersMapper;
import com.ycw.service.guoguo.ProjectReviewService;
import com.ycw.util.MailUtil;
import com.ycw.util.Msg;
/**
 * 项目审核功能
 */
@Service
public class ProjectReviewServiceImpl implements ProjectReviewService {

	@Autowired
	private ProjectsMapper projectsMapper;
	@Autowired
	private UsersMapper usersMapper;
	@Autowired
	private ProjectsTypeMapper projectsTypeMapper;
	
	@Override
	public Msg getProjectNotReviewInfoById(Integer primaryKey) {
		Projects projects = projectsMapper.selectByPrimaryKey(primaryKey);
		Users users = usersMapper.selectByPrimaryKey(projects.getPsUsId());
		ProjectsType projectsType = projectsTypeMapper.selectByPrimaryKey(projects.getPsPstId());
		return Msg.success().add("projects", projects).add("users", users).add("projectsType", projectsType);
		
	}

	@Override
	public Msg ProjectAuditSuccessful(Integer primaryKey) {
		Projects projects = new Projects();
		projects.setPsType(1);
		projects.setPsId(primaryKey);
		projectsMapper.updateByPrimaryKeySelective(projects);
		return Msg.success();
	}

	@Override
	public Msg ProjectAuditFailure(Integer primaryKey) {
		Projects projects = new Projects();
		projects.setPsType(5);
		projects.setPsId(primaryKey);
		projectsMapper.updateByPrimaryKeySelective(projects);
		return Msg.success();
	}

	@Override
	public Msg sendMailWhenProjectAuditFailureById(Integer primaryKey, String message) {
		Projects projects = projectsMapper.selectByPrimaryKey(primaryKey);
		Users users = usersMapper.selectByPrimaryKey(projects.getPsUsId());
		MailUtil.ProjectAuditFailure(users.getUsEmail(), message);
		return Msg.success();
	}

}
